package com.springboot.controller;

import com.springboot.config.redis.CacheService;
import com.springboot.config.redis.cluster.CacheClusterService;
import com.springboot.config.redis.cluster.RedisUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import redis.clients.jedis.Jedis;
import redis.clients.jedis.JedisPool;

@Controller
public class RedisController {

    @Autowired
    JedisPool jedisPool;

    @Autowired
    CacheService cacheService;
    @Autowired
    CacheClusterService cacheClusterService;


    @Autowired
    RedisUtil redisUtil;

    @RequestMapping(value = "/redis/set")
    public void set(){
        try (Jedis jedis = jedisPool.getResource()) {
            jedis.setex("haha", 10000, "1");
        }
    }

    @RequestMapping(value = "/redis/set1")
    public void set1(){
        cacheService.setex("heihei",1000,"111");
    }

    @RequestMapping("/redis")
    public String findRedis() {
        redisUtil.set("key100", "666");
        return redisUtil.get("key100");
    }

    @RequestMapping("/test1")
    public void set2(){
        cacheClusterService.set("hahah","dssd");
    }
}
